package com.example.utils;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;

public class Activity extends AppCompatActivity {

    public Button button,bundle;
    public FrameLayout frameLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_);
        frameLayout = findViewById(R.id.frameLayoutBundle);
        button = findViewById(R.id.bundle);
        bundle = findViewById(R.id.bundle1);
        initFragment();
    }

    public void initFragment(){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("a","成功");
                FragmentWithBundle fragmentWithBundle = new FragmentWithBundle(bundle);
                fragmentWithBundle.setArguments(bundle);
                Log.d("TAG", "onClick: 成功发出");
                show(fragmentWithBundle);
            }
        });

        bundle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
    private void show(Fragment fragment){
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frameLayoutBundle,fragment);
        transaction.commit();
    }
}